<!--
 * @Author: wangwang 2723008256@qq.com
 * @Date: 2022-05-11 15:26:59
 * @LastEditors: 番茄炒蛋蛋 wzh15802755802@163.com
 * @LastEditTime: 2024-03-14 14:53:50
 * @FilePath: \jzjypc4.0\src\views\PersonalCenter\PersonalMsg\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <!-- 个人中心/我的下载 -->
  <div id="container">
    <div class="content">
      <div class="top">
        <span></span>
        <h3>我的下载</h3>
      </div>
      <div class="box">
        <div class="taps">
          <div
            class="computer"
            :class="{ choseTap: tapRadio == 1 }"
            @click="choseComputer"
          >
            <h3>电脑端下载</h3>
            <span></span>
          </div>
          <div
            class="wechat1"
            :class="{ choseTap: tapRadio == 2 }"
            @click="choseWechat"
          >
            <h3>小程序端下载</h3>
            <span></span>
          </div>
          <div class="search">
            <input
              type="text"
              placeholder="请输入关键词搜索"
              v-model="value"
              @keydown.enter="search"
            />
            <i class="el-icon-search"></i>
          </div>
        </div>
        <div class="fileBox" v-for="(item, index) in downLondList" :key="index">
          <div class="pic">
            <img
              src="../../../assets/img/resFile (1).png"
              alt="file_url"
              v-if="
                item.suffix == 'ppt' ||
                item.suffix == 'pptx' ||
                item.suffix == 'ppsx' ||
                item.suffix == 'pps'
              "
            />
            <img
              src="../../../assets/img/resFile (2).png"
              alt="file_url"
              v-if="item.suffix == 'mp4' || item.suffix == 'rm'"
            />
            <img
              src="../../../assets/img/resFile (3).png"
              alt="file_url"
              v-if="item.suffix == 'xls' || item.suffix == 'xlsx'"
            />
            <img
              src="../../../assets/img/resFile (4).png"
              alt="file_url"
              v-if="item.suffix == 'zip' || item.suffix == 'rar'"
            />
            <img
              src="../../../assets/img/resFile (5).png"
              alt="file_url"
              v-if="item.suffix == 'm4a' || item.suffix == 'mp3'"
            />
            <img
              src="../../../assets/img/resFile (6).png"
              alt="file_url"
              v-if="item.suffix == 'doc' || item.suffix == 'docx'"
            />
            <img
              src="../../../assets/img/resFile (7).png"
              alt="file_url"
              v-if="item.suffix == 'pdf'"
            />
            <img
              src="../../../assets/img/resFile (8).png"
              alt="file_url"
              v-if="item.suffix == 'png' || item.suffix == 'jpg'"
            />
          </div>
          <div class="msg">
            <div class="title">
              <span v-if="false">推荐</span>
              <h4 @click="goresDetails(item.id)">{{ item.title }}</h4>
            </div>
            <p v-html="item.intro" v-if="item.suffix == 'zip'"></p>
            <div class="bottom">
              <span>下载于 {{ timeStamp2String(item.xz_time * 1000, 2) }}</span>
              <!-- <span><i class="el-icon-view"></i> {{ item.viewCount }}</span> -->
            </div>
          </div>
          <div class="downLoadAgain">
            <div class="download" @click="downLoad(item.id)">重新下载</div>
            <div
              class="download"
              style="background: #ff5a5a"
              @click="del_xzjl(item.log_id)"
            >
              删除记录
            </div>
          </div>
        </div>
        <div class="nothing" v-show="downLondList.length == 0">
          <img src="../../../assets/img/nothing.png" alt="" />
        </div>
        <!-- 分页部分 -->
        <div class="page1" v-if="downLondList.length > 0">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage"
            background
            :page-sizes="[5, 10, 20]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="counts"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { xzjl, url_kejian, del_xzjl } from "../../../api/http";
import { timeStamp2String } from "../../../utils/time";
export default {
  name: "changeClass",
  components: {},
  data() {
    return {
      timeStamp2String,
      tapRadio: 1, //当前tap值
      currentPage: 1, //分页默认选中页
      page: 1, //页码
      page_size: 5, //分页大小
      downLondList: [], //下载记录列表
      counts: 0, //总数据数
      value: "", //搜索框
    };
  },
  created() {
    //获取我的下载记录
    xzjl({
      md5key: localStorage.getItem("md5key"),
      from_str: this.tapRadio == 1 ? "ajax" : "xcx",
      page: 1,
      page_size: 5,
    }).then((res) => {
      if (res.retInt == 1) {
        console.log(res, "我的下载记录，默认电脑端");
        this.downLondList = res.retRes;
        this.counts = res.retCounts;
      } else {
        this.$notify.closeAll();
        this.$notify({
          message: res.retErr,
          duration: 2000,
          showClose: false,
        });
      }
    });
  },
  methods: {
    //选择电脑端下载
    choseComputer() {
      this.tapRadio = 1;
      this.currentPage = 1;
      //获取我的下载记录
      xzjl({
        md5key: localStorage.getItem("md5key"),
        title: this.value.trim(),
        from_str: "ajax",
        page: 1,
        page_size: this.page_size,
      }).then((res) => {
        if (res.retInt == 1) {
          console.log(res, "我的下载记录电脑端");
          this.downLondList = res.retRes;
          this.counts = res.retCounts;
        } else {
          this.$notify.closeAll();
          this.$notify({
            message: res.retErr,
            duration: 2000,
            showClose: false,
          });
        }
      });
    },
    //选择小程序端下载
    choseWechat() {
      this.tapRadio = 2;
      this.currentPage = 1;
      console.log(this.tapRadio);
      //获取我的下载记录
      xzjl({
        md5key: localStorage.getItem("md5key"),
        title: this.value.trim(),
        from_str: "xcx",
        page: 1,
        page_size: this.page_size,
      }).then((res) => {
        if (res.retInt == 1) {
          console.log(res, "我的下载记录小程序端");
          this.downLondList = res.retRes;
          this.counts = res.retCounts;
        } else {
          this.$notify.closeAll();
          this.$notify({
            message: res.retErr,
            duration: 2000,
            showClose: false,
          });
        }
      });
    },
    //搜索下载内容
    search() {
      //获取我的下载记录
      this.page = 1;
      this.currentPage = 1;
      xzjl({
        md5key: localStorage.getItem("md5key"),
        title: this.value.trim(),
        from_str: this.tapRadio == 1 ? "ajax" : "xcx",
        page: 1,
        page_size: this.page_size,
      }).then((res) => {
        if (res.retInt == 1) {
          console.log(res, "我的下载记录，默认电脑端");
          this.downLondList = res.retRes;
          this.counts = res.retCounts;
        } else {
          this.$notify.closeAll();
          this.$notify({
            message: res.retErr,
            duration: 2000,
            showClose: false,
          });
        }
      });
    },
    //获取文件下载链接
    downLoad(id) {
      url_kejian({
        md5key: localStorage.getItem("md5key"),
        id: id,
      }).then((res) => {
        console.log(res);
        // window.open(res.retRes.download_file_url, "_blank");
        let url = res.retRes.download_file_url;
        const a = document.createElement("a");
        a.href = url;
        a.download = res.retRes.title;
        a.style.display = "none";
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
      });
    },
    //删除下载记录
    del_xzjl(id) {
      console.log(id);
      console.log([id]);
      del_xzjl({
        md5key: localStorage.getItem("md5key"),
        del_ids: [id],
      }).then((res) => {
        if (res.retInt == 1) {
          xzjl({
            md5key: localStorage.getItem("md5key"),
            title: this.value.trim(),
            from_str: this.tapRadio == 1 ? "ajax" : "xcx",
            page: this.page,
            page_size: this.page_size,
          }).then((res) => {
            if (res.retInt == 1) {
              console.log(res, "我的下载记录，默认电脑端");
              this.downLondList = res.retRes;
              this.counts = res.retCounts;
              this.$notify({
                message: "删除成功",
                duration: 2000,
                showClose: false,
              });
            }
          });
        }
      });
    },
    //调整每页条数
    handleSizeChange(val) {
      console.log(val);
      this.page_size = val;
      //获取我的下载记录
      xzjl({
        md5key: localStorage.getItem("md5key"),
        title: this.value.trim(),
        from_str: this.tapRadio == 1 ? "ajax" : "xcx",
        page: this.page,
        page_size: this.page_size,
      }).then((res) => {
        if (res.retInt == 1) {
          console.log(res, "我的下载记录，默认电脑端");
          this.downLondList = res.retRes;
          this.counts = res.retCounts;
        } else {
          this.$notify.closeAll();
          this.$notify({
            message: res.retErr,
            duration: 2000,
            showClose: false,
          });
        }
      });
    },
    //跳转到第几页
    handleCurrentChange(val) {
      this.page = val;
      //获取我的下载记录
      xzjl({
        md5key: localStorage.getItem("md5key"),
        title: this.value.trim(),
        from_str: this.tapRadio == 1 ? "ajax" : "xcx",
        page: this.page,
        page_size: this.page_size,
      }).then((res) => {
        if (res.retInt == 1) {
          console.log(res, "我的下载记录，默认电脑端");
          this.downLondList = res.retRes;
          this.counts = res.retCounts;
        } else {
          this.$notify.closeAll();
          this.$notify({
            message: res.retErr,
            duration: 2000,
            showClose: false,
          });
        }
      });
    },
    //前往课件详情页
    goresDetails(id) {
      this.$router.push({
        path: "/resource/resDetails?id",
        query: {
          id: id,
          name: "我的下载",
          path: this.$route.fullPath,
        },
      });
    },
  },
};
</script>
<style>
.page1 {
  width: 800px;
  margin: 0 auto;
}
.el-pagination {
  text-align: center;
  margin: 20px 80px 20px 0;
}
.el-select .el-input.is-focus .el-input__inner {
  border-color: #08a579 !important;
}
.el-pagination .el-select .el-input .el-input__inner:hover {
  border-color: #08a579 !important;
}
.el-select .el-input__inner:focus {
  border-color: #08a579 !important;
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #08a579;
}
.el-pagination.is-background .el-pager li:not(.disabled).active:hover {
  color: #fff;
}
.el-pager li:hover {
  color: #08a579 !important;
}
.el-select-dropdown__item.selected {
  color: #08a579 !important;
}
.el-pagination__editor.el-input .el-input__inner {
  border-color: #ccc;
}
</style>
<style lang="less" scoped>
#container {
  .content {
    .top {
      display: flex;
      margin: 30px 0px 40px 30px;
      span {
        display: inline-block;
        position: relative;
        top: 5px;
        margin-right: 10px;
        width: 3px;
        height: 20px;
        background: #08a579;
        border-radius: 2px;
      }
      h3 {
        font-size: 20px;
      }
    }
    .box {
      .taps {
        position: relative;
        display: flex;
        align-items: center;
        margin-left: 30px;
        width: 870px;
        height: 38px;
        border-bottom: 1px solid #e6e6e6;
        overflow: hidden;
        .computer {
          display: flex;
          flex-direction: column;
          align-items: center;
          margin: 0 30px 0px 20px;
          cursor: pointer;
          h3 {
            padding-bottom: 10px;
            color: #939599;
            font-size: 14px;
          }
          span {
            display: inline-block;
            width: 32px;
            height: 3px;
            border-radius: 10px;
          }
        }
        .wechat1 {
          display: flex;
          flex-direction: column;
          align-items: center;
          cursor: pointer;
          h3 {
            padding-bottom: 10px;
            color: #939599;
            font-size: 14px;
          }
          span {
            display: inline-block;
            width: 32px;
            height: 3px;
            border-radius: 10px;
          }
        }
        //活动样式
        .choseTap {
          h3 {
            font-size: 16px;
            color: #333;
          }
          span {
            background: #08a579;
          }
        }
        .search {
          position: relative;
          position: absolute;
          top: 0px;
          right: 30px;
          input {
            padding-left: 30px;
            width: 170px;
            height: 30px;
            background: #ffffff;
            border: 1px solid #c4c7cc;
            border-radius: 16px;
            outline: none;
          }
          i {
            position: absolute;
            top: 7px;
            left: 10px;
            font-size: 18px;
            color: #c4c7cc;
          }
        }
      }
      .fileBox {
        display: flex;
        // justify-content: space-between;
        // align-items: center;
        margin-left: 40px;
        padding-bottom: 20px;
        margin-top: 20px;
        border-bottom: 1px solid #e6e6e6;
        .pic {
          display: flex;
          justify-content: center;
          align-items: center;
          width: 140px;
          height: 140px;
          background: linear-gradient(0deg, #e6e6e6, #ffffff);
          border: 1px solid #ededed;
        }
        .msg {
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          margin-left: 15px;
          width: 520px;
          .title {
            // display: flex;
            position: relative;
            span {
              position: absolute;
              display: inline-block;
              text-align: center;
              width: 40px;
              height: 20px;
              background: #f85230;
              border-radius: 4px;
              color: #fff;
              font-size: 14px;
            }
            h4 {
              margin-bottom: 14px;
              width: 480px;
              font-size: 15px;
              color: #333;
              font-weight: 600;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box; //使用自适应布局
              -webkit-line-clamp: 2; //设置超出行数，要设置超出几行显示省略号就把这里改成几
              -webkit-box-orient: vertical;
            }
          }
          p {
            width: 480px;
            min-height: 65px;
            max-height: 165px;
            font-size: 13px;
            color: #626366;
            overflow: hidden;
          }
          .bottom {
            span {
              margin-right: 20px;
              font-size: 12px;
              color: #939599;
            }
          }
        }
        .downLoadAgain {
          height: 142px;
          border-left: 1px solid #e6e6e6;
          .download {
            margin-left: 30px;
            margin-top: 28px;
            width: 96px;
            height: 28px;
            font-size: 18px;
            color: #f5f5f5;
            text-align: center;
            line-height: 28px;
            border-radius: 4px;
            font-size: 14px;
            background: #08a579;
            border-radius: 14px;
            cursor: pointer;
          }
          .download:active {
            opacity: 0.8;
          }
        }
      }
      .fileBox:hover {
        cursor: pointer;
        .title {
          h4 {
            color: #08a579;
          }
        }
      }
      .nothing {
        margin-top: 100px;
        text-align: center;
        img {
          // width: 400px;
        }
      }
    }
  }
}
</style>
